{extend name="admin@index_layout"/}
{block name="main"}
<form class="layui-form" method="post" lay-filter="layui-form">
    <div class="layui-tab">
        <ul class="layui-tab-title">
            <li class="layui-this">基本设置</li>
            <li>选项设置</li>
            <li id="modeTab">模板设置</li>
            <li id="authTab">权限设置</li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <div class="alert alert-warning-light">温馨提示<br>列表类型的模型一旦选择后不支持更换其他模型<br>列表改成单页或外链类型后，无法在改回列表类型</div>
                <div class="layui-form-item">
                    <label class="layui-form-label">类型</label>
                    <div class="layui-input-block">
                        <input type="radio" name="type" value="1" title="单页" lay-filter="type">
                        <input type="radio" name="type" value="2" title="列表" checked lay-filter="type">
                        <input type="radio" name="type" value="3" title="外链" lay-filter="type">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">上级菜单</label>
                    <div class="layui-input-block">
                        <select name="parentid">
                            <option value="0">作为顶级栏目</option>
                            {$category|raw}
                        </select>
                    </div>
                </div>
                <div class="layui-form-item lay lay-list">
                    <label class="layui-form-label">选择模型</label>
                    <div class="layui-input-block">
                        <select name="modelid" lay-filter="filter">
                            <option value="0">请选择模型</option>
                            {volist name="models" id="vo"}
                            <option value="{$vo.id}" {if condition=" $parentid_modelid eq $vo['id'] "}selected{/if}>{$vo.name}</option>
                            {/volist}
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">添加方式</label>
                    <div class="layui-input-block">
                        <input type="radio" name="isbatch" value="1" title="批量添加" lay-filter="filter">
                        <input type="radio" name="isbatch" value="0" title="单条添加" checked lay-filter="filter">
                    </div>
                </div>
                <div class="layui-form-item" id="normal_add">
                    <label class="layui-form-label">栏目标题 </label>
                    <div class="layui-input-block">
                        <input type="text" name="catname" lay-verify="required" autocomplete="off" placeholder="栏目名称" class="layui-input" id="catname">
                    </div>
                </div>
                <div class="layui-form-item" id="catdir_tr">
                    <label class="layui-form-label">唯一标识</label>
                    <div class="layui-input-block">
                        <input type="text" name="catdir" autocomplete="off" placeholder="唯一标识" class="layui-input" id="catdir">
                    </div>
                    <div class="layui-form-mid2 layui-word-aux">英文数字组成，留空则自动生成拼音</div>
                </div>
                <div class="layui-form-item lay lay-url">
                    <label class="layui-form-label">链接地址</label>
                    <div class="layui-input-block">
                        <div class="layui-input-inline w300">
                            <input type="text" name="url"  autocomplete="off" placeholder="自定义链接地址" class="layui-input" id="url">
                        </div>
                        <div class="layui-input-inline">
                            <select lay-filter="fasttype">
                                <option data-url="">常用内部链接</option>
                                <option data-url="cms/index/index">首页</option>
                                {if $cmsConfig['site_url_mode']==1}
                                <option data-url="cms/index/lists?catid=2">列表页/单页</option>
                                <option data-url="cms/index/shows?catid=2&id=1">详情页</option>
                                {else}
                                <option data-url="cms/index/lists?catdir=Introduction">列表页/单页</option>
                                <option data-url="cms/index/shows?catdir=Introduction&id=1">详情页</option>
                                {/if}
                                {php}$info=get_addon_info('formguide');{/php}
                                {if $info && $info['status']>0}
                                <option data-url="index/formguide/index?id=2">表单页</option>
                                {/if}
                            </select>
                        </div>
                    </div>
                    <div style="clear: both;"></div>
                    <div class="layui-form-mid2 layui-word-aux">有值时生效，内部链接格式:模块/控制器/操作?参数=参数值&...，外部链接则必须http://开头</div>
                </div>
                <div class="layui-form-item" id="batch_add" style="display:none">
                    <label class="layui-form-label">栏目名称</label>
                    <div class="layui-input-block">
                        <textarea name="batch_add" lay-verify="" placeholder="栏目名称|唯一标识" class="layui-textarea"></textarea>
                    </div>
                    <div class="layui-form-mid2 layui-word-aux">例如：<br>国内新闻|china<br>国际新闻|world<br>唯一标识留空时自动生成拼音</div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">栏目简介</label>
                    <div class="layui-input-block">
                        <textarea name="description" placeholder="栏目简介" class="layui-textarea"></textarea>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">栏目图片</label>
                    <div class="layui-input-block">
                        <div class="js-upload-image">
                            {:Form::image("image")}
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">栏目图标</label>
                    <div class="layui-input-block">
                        <div class="js-upload-image">
                            {:Form::image("icon")}
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-tab-item">
                <div class="layui-form-item">
                    <label class="layui-form-label">在导航显示</label>
                    <div class="layui-input-block">
                        <input type="radio" name="status" value="1" title="显示" checked>
                        <input type="radio" name="status" value="0" title="隐藏">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">显示排序</label>
                    <div class="layui-input-block">
                        <input type="text" name="listorder" autocomplete="off" placeholder="显示排序" class="layui-input" value="100">
                    </div>
                </div>
                <div class="layui-form-item web_seo">
                    <label class="layui-form-label">网页标题</label>
                    <div class="layui-input-block">
                        <input type="text" name="setting[meta_title]" autocomplete="off" placeholder="针对搜索引擎设置的标题" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item web_seo">
                    <label class="layui-form-label">网页关键词</label>
                    <div class="layui-input-block">
                        <input type="text" name="setting[meta_keywords]" autocomplete="off" placeholder="关键字中间用半角逗号隔开" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item web_seo">
                    <label class="layui-form-label">网页描述</label>
                    <div class="layui-input-block">
                        <textarea name="setting[meta_description]"  placeholder="针对搜索引擎设置的网页描述" class="layui-textarea"></textarea>
                    </div>
                </div>
            </div>
            <div class="layui-tab-item">
                <div class="lay lay-list">
                    <div class="layui-form-item">
                        <label class="layui-form-label">栏目首页模板</label>
                        <div class="layui-input-block">
                            <select name="setting[category_template]">
                                <option value="category.html" selected>默认栏目首页:category.html</option>
                                {volist name="tp_category" id="vo"}
                                <option value="{$vo}">{$vo}</option>
                                {/volist}
                            </select>
                        </div>
                        <div class="layui-form-mid2 layui-word-aux">新增模板以category_xx.html形式,【含有子栏目时生效】</div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">栏目列表页模板</label>
                        <div class="layui-input-block">
                            <select name="setting[list_template]">
                                <option value="list.html" selected>默认栏目列表页:list.html</option>
                                {volist name="tp_list" id="vo"}
                                <option value="{$vo}">{$vo}</option>
                                {/volist}
                            </select>
                        </div>
                        <div class="layui-form-mid2 layui-word-aux">新增模板以list_xx.html形式,【没有子栏目时生效】</div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">内容页模板</label>
                        <div class="layui-input-block">
                            <select name="setting[show_template]">
                                <option value="show.html" selected>默认内容页:show.html</option>
                                {volist name="tp_show" id="vo"}
                                <option value="{$vo}">{$vo}</option>
                                {/volist}
                            </select>
                        </div>
                        <div class="layui-form-mid2 layui-word-aux">新增模板以show_xx.html形式</div>
                    </div>
                </div>
                <div class="layui-form-item lay lay-page">
                    <label class="layui-form-label">单页模板</label>
                    <div class="layui-input-block">
                        <select name="setting[page_template]">
                            <option value="page.html" selected>默认内容页:page.html</option>
                            {volist name="tp_page" id="vo"}
                            <option value="{$vo}">{$vo}</option>
                            {/volist}
                        </select>
                    </div>
                    <div class="layui-form-mid2 layui-word-aux">新增模板以page_xx.html形式</div>
                </div>
            </div>
            <div class="layui-tab-item">
                <div class="layui-form-item">
                    <label class="layui-form-label">会员组权限</label>
                    <table class="layui-table" style="max-width: 250px;">
                      <colgroup>
                        <col width="150">
                        <col width="100">
                      </colgroup>
                      <thead>
                        <tr>
                          <th>会员组名称</th>
                          <th>允许投稿</th>
                        </tr> 
                      </thead>
                      <tbody>
                        {volist name="Member_Group" id="vo"}
                        <tr>
                          <td>{$vo.name}</td>
                          <td><input type="checkbox" name="priv_groupid[]" value="add,{$vo.id}" title="允许" lay-skin="primary"></td>
                        </tr>
                        {/volist}
                      </tbody>
                    </table>
                </div>
            </div>
        </div>
        <div class="layui-form-item layer-footer">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit>立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </div>
</form>
{/block}
{block name="script"}
<script type="text/javascript">
layui.use(['form','yznForm'], function(){
	var form = layui.form,
    yznForm = layui.yznForm;

    yznForm.listen();

    form.on('radio(type)', function(data){
      $(".lay").addClass("layui-hide");
      //单页
      if(data.value==1){
        $('#modeTab').show();
        $('#authTab').hide();
        $('.lay-page').removeClass("layui-hide");
      }
      //列表
      if(data.value==2){
        $('#modeTab').show();
        $('#authTab').show();
        $('.lay-list').removeClass("layui-hide");
      }
      //外链
      if(data.value==3){
        $('#authTab').hide();
        $('#modeTab').hide();
        $('.lay-url').removeClass("layui-hide");
      }
    });
    $("input[name='type'][value=2]").next().trigger("click");

	form.on('radio(filter)', function(data){
		if(1==data.value){
			//批量
			$('#normal_add').hide();
			$('#catdir_tr').hide();
			$('#batch_add').show();
			$('#catname').attr('disabled',true).attr('lay-verify','');

		}
		if(0==data.value){
			$('#normal_add').show();
			$('#catdir_tr').show();
			$('#batch_add').hide();
			$('#catname').attr('disabled',false).attr('lay-verify','required');
		}
	});

    form.on('select(fasttype)', function(data) {
        $('#url').val($(data.elem).find("option:selected").attr("data-url"));
    });

    form.on('select(filter)', function(data){
        //console.log(data.value); //得到被选中的值
        if(!isNaN(data.value)){
            $.get('{:url("public_tpl_file_list")}', {id:data.value}, function(res) {
                if(res.code==0){
                    form.val("layui-form", {
                       "setting[category_template]": res.data.category_template,
                       "setting[list_template]": res.data.list_template,
                       "setting[show_template]": res.data.show_template,
                    })
                }
            });
        }
    });

    {if $parentid_modelid}
        $.get('{:url("public_tpl_file_list")}', {id:{$parentid_modelid}}, function(res) {
            if(res.code==0){
                form.val("layui-form", {
                   "setting[category_template]": res.data.category_template,
                   "setting[list_template]": res.data.list_template,
                   "setting[show_template]": res.data.show_template,
                })
            }
        });
    {/if}

});
</script>
{/block}
